import _ from "lodash";
// 删除sheet中的一个列

// expect input like (3,{ name: 'ExportOrderList5965953099', data: [ [Array] ] })
// 输入要删除的列序号 不传返回源
function rmCol(sheet: Sheet, index?: number): Sheet {
  let res: Sheet = { name: sheet.name, data: [] };
  _(sheet.data).each((strs: string[]) => {
    _.remove(strs, (str, i) => i === index);
    res.data.push(strs);
  });
  return res;
}

function emptyCol(sheet: Sheet, index?: number): Sheet {
  let res: Sheet = { name: sheet.name, data: [] };
  _(sheet.data).each((strs: string[]) => {
    res.data.push(
      strs.map((str, i) => {
        let r = str;
        if (i === index) {
          r = "";
        }
        return r;
      })
    );
  });
  return res;
}

export { rmCol, emptyCol };
